package cn.micro.system.manage.service.impl;

import cn.micro.system.manage.entity.AssetDimProductInfo;
import cn.micro.system.manage.entity.AssetDimProductVersion;
import cn.micro.system.manage.entity.dto.AssetDimProductSearch;
import cn.micro.system.manage.mapper.AssetDimProductInfoMapper;
import cn.micro.system.manage.service.AssetDimProductInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.function.Consumer;

/**
 * <p>
 * 产品信息 服务实现类
 * </p>
 *
 * @author wr
 * @since 2024-01-05
 */
@Service
public class AssetDimProductInfoServiceImpl extends ServiceImpl<AssetDimProductInfoMapper, AssetDimProductInfo> implements AssetDimProductInfoService {

    @Override
    public List<AssetDimProductInfo> listByPage(int page, int size, AssetDimProductSearch search) {
        PageHelper.startPage(page, size);
        return this.baseMapper.queryByPage(search);
    }

    @Override
    public AssetDimProductInfo detail(Long id) {
        return this.baseMapper.queryById(id);
    }

    @Override
    public List<AssetDimProductInfo> getByCodeOrName(AssetDimProductInfo assetDimProductInfo) {
        LambdaQueryWrapper<AssetDimProductInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(assetDimProductInfoLambdaQueryWrapper -> assetDimProductInfoLambdaQueryWrapper.eq(StringUtils.isNotEmpty(assetDimProductInfo.getCode()), AssetDimProductInfo::getCode, assetDimProductInfo.getCode())
                .or().eq(StringUtils.isNotEmpty(assetDimProductInfo.getName()), AssetDimProductInfo::getName, assetDimProductInfo.getName())).ne(StringUtils.isNotEmpty(assetDimProductInfo.getId()), AssetDimProductInfo::getId, assetDimProductInfo.getId());
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional
    public boolean pub(AssetDimProductVersion productVersion) {
        return false;
    }
}
